package com.foreverwin.mes.common.controller;

import com.foreverwin.mes.common.constants.HandleBOConstants;
import com.foreverwin.mes.common.model.MobileWorkStationData;
import com.foreverwin.mes.common.service.MobileWorkStationService;
import com.foreverwin.mes.core.base.AjaxResult;
import com.foreverwin.mes.core.utils.CommonMethods;
import com.foreverwin.mes.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author Syngna
 * @since 2020-01-04
 */
@RestController
@RequestMapping("/mobileWorkStations")
public class MobileWorkStationController {

    @Autowired
    public MobileWorkStationService mobileWorkStationService;

    @GetMapping("listMobileWorkStationApplication")
    public AjaxResult listMobileWorkStationApplication(String workStation) {

        List<MobileWorkStationData> result;
        try {
            String site = CommonMethods.getSite();
            String user = CommonMethods.getUser();
            String userBo = StringUtils.genHandle(HandleBOConstants.USER_BO, site, user);
            result = mobileWorkStationService.listMobileWorkStationApplication(site, userBo, workStation);
        }
        catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(result);
    }
}